package org.example.userdata;

import org.example.ConnectDatabase;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class TestUser extends ConnectDatabase {
    public String testUser(User user){
        new ConnectDatabase();
        Statement sql;
        ResultSet rs;
        User result;
        String str = "select * from Users where ID = '"+user.ID+"'";
        String imf = null;
        try {
            sql = con.createStatement();
            rs = sql.executeQuery(str);
            if (rs.next()) {
                result = new User();
                result.setID(rs.getString(1));
                result.setName(rs.getString(2));
                result.setUser_Class(rs.getBoolean(3));
                result.setPassword(rs.getString(4));
                if (result.ID == null){
                    imf = "查无此账户";
                } else if (result.password.equals(user.password) && result.user_Class ) {
                    imf = "学生登录成功"+"ID:"+result.ID+"name:"+result.name;
                }else if (result.password.equals(user.password) && !result.user_Class ) {
                    imf = "老师登录成功";
                }else imf = "账号密码不对";
            }
            con.close();
        }catch (SQLException e){}
        return imf;
    }
}
